<html>
  <head>
    <script type="text/javascript" src="js/biginteger.js"></script>
    <script type="text/javascript" src="js/substandard_lisp.js"></script>
    <script type="text/substandard-lisp">
% slnil - substandard lisp nil interpreter
% author: Nicky Nickell <nicky.nickell@gmail.com>

(de linkify (src &optional text)
  (let ((link (dom-create "a")))
    (dom-set-attribute link "href" src)
    (dom-append link (or text src))
    link))

(de run-nil nil
  (prog (output input program atoms atom-length) % let* sure would be nice...
    (setq output (dom-get-element-by-id "output"))
    (setq input (dom-get-element-by-id "input"))
    (setq program (dom-get-value input))
    (setq atoms (string-split program " "))
    (setq atom-length (length atoms))
    (dom-clear output)
    (dom-append output 
      "program found: " program "<br><br>beginning atomization...<br>")
    (apply #'dom-append 
           (cons output
                (mapcar atoms 
                        (lambda (a) 
                          (string-concat "found atom: " a "<br>")))))
    (dom-append output 
      "atomization complete: " atom-length " atoms found<br><br>"
      "beginning translation...<br>"
      (string-repeat "converted atom: NOP<br>" 
                     atom-length)
      "translation complete<br><br>beginning optimization...<br>"
      (string-repeat "optimized NOP NOP: NOP<br>" 
                     (sub1 atom-length))
      "optimization complete<br><br>compiled code: NOP")))

(progn
  (dom-set-title "slnil")
  (dom-append (dom-get-body)
    "see:<br>"
    (linkify "http://www.leib.be/sascha/the-nil-programming-language/") "<br>"
    (linkify "http://www.esolangs.org/wiki/Nil") "<br>"
    (linkify 
      "http://www.safalra.com/programming/esoteric-languages/interpreters/nil/")
    "<br><br>"
    (dom-create-text (pair '("id" "value") 
                           '("input" "I wondered lonely as a cloud")))
    (dom-create-button "evaluate" nil '(("onclick" . (run-nil))))
    "<br>output:<br>"
    (dom-create "div" '(("id" . "output")))))

    </script>
  </head>
  <body>
  </body>
</html>
